#!/usr/local/bin/lua
p1={name='wzq',age=33,sex='male'}
print(p1)
print(p1.name)
print(p1['name'])
-- travels table
for k,v in pairs(p1) do
	print(k,v)
end


p2={[1]=123,['name']='haha'}
print(p2.name);
--print(p2.1); -- error
print(p2[1])


-- array
local arr={11,22,33}
for i=1, #arr do --#arr = length of arr
	print(arr[i])
end


for k,v in pairs(arr) do
	print(k,v)
end

fraction_a={n=2,dn=3}
fraction_b={n=4,dn=7}
fraction_op={}
fraction_op.__add=function(f1,f2)
	ret={}
	ret.n=f1.n*f2.dn+f1.dn*f2.n
	ret.dn=f1.dn*f2.dn
	return ret
end

fraction_s=fraction_op.__add(fraction_a,fraction_b)
print(fraction_s['n'],fraction_s.dn)


setmetatable(fraction_a,fraction_op)
setmetatable(fraction_b,fraction_op)
f_s=fraction_a+fraction_b;
print(f_s.n,f_s.dn)
